package com.hst.web.base.proxy;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

import com.hst.core.Page;
import com.hst.core.ServiceContext;
import com.hst.core.dao.IORDao;
import com.hst.core.dao.ISQLDao;
import com.hst.core.dao.ORQuery;
import com.hst.core.dao.ORQuery.Op;
import com.hst.core.json.JsonUtil;
import com.hst.core.meta.MetaData;
import com.hst.core.meta.proxies.DefaultDataProxy;
import com.hst.web.auth.po.User;
import com.hst.web.base.entity.TCompanyEmployee;
import com.hst.web.base.entity.TDeptEmployee;
import com.hst.web.base.service.UserRoleService;
import com.hst.web.base.ui.CompanyVehicle;
import com.hst.web.base.ui.PersoneltransferInfo;
import com.hst.web.base.ui.VehicleSub;


public class PersonItransferInfoProxy extends DefaultDataProxy{
	
	@Autowired
	IORDao dao;

	@Autowired
	ISQLDao sql;
	
	@Autowired
	UserRoleService us;
	
	@Override
	public Page<?> list(Map<String, ?> query, int pageIdx) {
		User u = (User) ServiceContext.getInstance().getUser();
		
		Map<String,Object> map = new HashMap<String, Object>();
		map = (Map<String, Object>) query;
		map.put("companyCodeOld", u.getCompanyCode());
		map.put("isContractor", null);
		Page<?> p = sql.list("employee.list-employee-transfer",map, pageIdx, Page.getPageSize());
		return p;
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public Object save(MetaData data) throws Exception {
		PersoneltransferInfo meta = (PersoneltransferInfo) data;
		if (1 == data.getOp()) {
			super.save(data);
		}
		String employeeCode = meta.getEmployeeCode();
		TCompanyEmployee companyEmployee= dao.get(TCompanyEmployee.class, employeeCode);
		meta.setFullname(companyEmployee.getFullname());
		return meta;
	}
}
